package toWeka;

import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

public class Day {
	private Date date;
	private double morning;//5 - 12
	private double afternoon;//12-17
	private double evening;//17-22
	private double night;//22-5
	private double total;
	
	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public double getMorning() {
		return morning;
	}

	public void setMorning(double morning) {
		this.morning = morning;
	}

	public double getAfternoon() {
		return afternoon;
	}

	public void setAfternoon(double afternoon) {
		this.afternoon = afternoon;
	}

	public double getEvening() {
		return evening;
	}

	public void setEvening(double evening) {
		this.evening = evening;
	}

	public double getNight() {
		return night;
	}

	public void setNight(double night) {
		this.night = night;
	}

	
	
	public Day (ArrayList<Minute> m){
		Double mo=0.;
		Double af=0.;
		Double ev=0.;
		Double ni=0.;
		int cMo,cAf,cEv,cNi;
		cMo=0;
		cAf=0;
		cEv=0;
		cNi=0;
		Calendar cal = Calendar.getInstance();
		this.date = m.get(0).getDate();
		for (Minute min : m){
			cal.setTime(min.getTime());
			int h=cal.get(Calendar.HOUR_OF_DAY);
			if (h>=5 && h<12){
				if (min.getGlobal_active_power().compareTo("?")!=0){
					mo += Double.parseDouble(min.getGlobal_active_power());
					//cMo++;
				}
			}
			else if (h>=12 && h<17){
				if (min.getGlobal_active_power().compareTo("?")!=0){
					af += Double.parseDouble(min.getGlobal_active_power());
					//cAf++;
				}
			}
			else if (h>=17 && h<22){
				if (min.getGlobal_active_power().compareTo("?")!=0){
					ev += Double.parseDouble(min.getGlobal_active_power());
					//cEv++;
				}
			}
			else{
				if (min.getGlobal_active_power().compareTo("?")!=0){
					ni += Double.parseDouble(min.getGlobal_active_power());
					//cNi++;
				}
			}
		}
		/*if (cMo==0) cMo=1;
		if (cAf==0) cAf=1;
		if (cEv==0) cEv=1;
		if (cNi==0) cNi=1;*/
		this.morning=mo;
		this.afternoon=af;
		this.evening=ev;
		this.night=ni;
		
		this.total=mo+af+ev+ni;

	}
	
	@Override
	public String toString (){
		DecimalFormat df = new DecimalFormat("0.000"); 
		//por dia
		//return this.date.toString().substring(0, 11)+this.date.toString().substring(24)+";"+df.format(this.total);
		//por franja dias repetidos
		//return "noevodia\n"+this.date.toString().substring(0, 11)+this.date.toString().substring(24)+";"+df.format(this.morning)+"\n"+this.date.toString().substring(0, 11)+this.date.toString().substring(24)+";"+df.format(this.afternoon)+"\n"+this.date.toString().substring(0, 11)+this.date.toString().substring(24)+";"+df.format(this.evening)+";"+df.format(this.night)+";"+df.format(this.total);
		return "noevodia\n"+this.date.toString().substring(0, 11)+this.date.toString().substring(24)+";"+df.format(this.morning)+"\n"+this.date.toString().substring(0, 11)+this.date.toString().substring(24)+";"+df.format(this.afternoon)+"\n"+this.date.toString().substring(0, 11)+this.date.toString().substring(24)+";"+df.format(this.evening)+";"+df.format(this.night)+";"+df.format(this.total);
	}
}
